package com.moes.beta.dao;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class UserInfoSQLiteHelper {

    public static final String TBL_MC_APPS_USER = "TBL_MC_APPS_USER";
    public static final String _ID = "_ID";
    public static final String LOGIN_ID = "LOGIN_ID";
    public static final String USER_ID = "USER_ID";
    public static final String CREATE_TABLE = "CREATE TABLE " + TBL_MC_APPS_USER + " (" + _ID
            + " integer primary key autoincrement, " + LOGIN_ID + ", " + USER_ID + ");";

    private static UserInfoSQLiteHelper helper;
    private static SQLiteDatabase mSql;

    public static UserInfoSQLiteHelper getInstance(Context context) {
        mSql = MOESBaseHelper.getInstance(context).getWritableDatabase();
        if (helper != null) {
            return helper;
        }
        return helper = new UserInfoSQLiteHelper();
    }

    public Cursor getUserInfo() {
        Cursor cursor = mSql.query(TBL_MC_APPS_USER, new String[] { _ID, LOGIN_ID, USER_ID }, null, null, null, null,
                null);
        return cursor;
    }

    public boolean insertUserInfo(ContentValues userInfo) {
        boolean isSuccess = false;
        try {
            mSql.insert(TBL_MC_APPS_USER, null, userInfo);
            isSuccess = true;
        } catch (Exception e) {
            e.printStackTrace();
            isSuccess = false;
        }
        return isSuccess;
    }

    public boolean deleteUserInfo() {
        boolean isSuccess = false;
        try {
            mSql.delete(TBL_MC_APPS_USER, null, null);
            isSuccess = true;
        } catch (Exception e) {
            e.printStackTrace();
            isSuccess = false;
        }
        return isSuccess;
    }
}
